package com.principles.structure.bridging;

/**
 * @Description 桥接模式：将继承关系转化为关联关系，从而降低了类和类之间的偶合，减少代码的编写量。
 *                      将抽象和实现解耦，使得两者可以独立的变化。
 * @Date 2025/1/31 10:07
 **/
public class BridgingPattern {
    public static void main(String[] args) {
        Abstraction abstraction = new Bridging(new ConcreteImplementor());
        abstraction.doWork();

    }
}
class Bridging extends Abstraction{

    public Bridging(Implementor implementor) {
        super(implementor);
    }

    @Override
    public void test() {
        System.out.println("12");
    }
}

abstract class Abstraction{
    private Implementor implementor;

    abstract public void test();
    public Abstraction(Implementor implementor) {
        this.implementor = implementor;
    }
    public void doWork(){
        this.implementor.doSomething();
    }
}
// 实现接口
interface Implementor{
    public void doSomething();
}

// 实现类
class ConcreteImplementor implements Implementor{

    @Override
    public void doSomething() {
        System.out.println("hello world");
    }
}